# -*- coding: utf-8 -*-
"""
@author   : Wu Jiang Bin
@gitee   : https://gitee.com/wjbhydj
@software : PyCharm2021 
@file     : celery.py
@create   : 2022/8/27 11:27
"""
from celery import Celery
from kombu import Queue
from celery.schedules import crontab

app = Celery("proj_celery")

app.config_from_object('proj_celery.celery_config')

app.conf.update(
    task_ignore_result=True
)
# 定义队列
app.conf.task_queues = (
    Queue('blog_queue'),
    Queue('default_queue'),
)
# 使用队列路由
# app.conf.task_routes = {
#     'polls.tasks.*': {
#         'queue': 'queue_1',
#     },
#     'blog.tasks.add': {
#         'queue': 'queue_1',
#     },
#     'blog.tasks.minus': {
#         'queue': 'queue_2',
#     },
# }

# 设置默认队列
app.conf.task_default_queue = 'default_queue'

# 设置定时任务
app.conf.beat_schedule = {
    'add-every-30-seconds': {
        'task': 'proj_celery.sms.tasks.add',
        'schedule': 30,
        'args': (16, 16),
    },
    'schedule_test_add': {
        'task': 'proj_celery.email.tasks.mul',
        'schedule': crontab(minute="50", hour="23"),        # 定时策略
    },
}

if __name__ == "__main__":
    app.start()